package logic

import (
	"context"
	"sus/susclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AuthLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthLogic {
	return &AuthLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AuthLogic) Auth(req *types.AuthRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	auth, err := l.svcCtx.SusRpc.Auth(l.ctx, &susclient.AuthRequest{
		IDCard:   req.IDCard,
		RealName: req.RealName,
		UserId:   int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "是名人成功",
		Code:    200,
		Data:    auth,
	}, nil
}
